package com.central.common.feign;

import com.central.common.constant.ServiceNameConstants;
import com.central.common.enums.PrivilegeType;
import com.central.common.model.DatasourceInfo;
import com.central.common.model.Result;
import com.central.common.model.TableInfo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author td
 */
@FeignClient(name = ServiceNameConstants.DATA_MANAGE_SERVICE, decode404 = true)
public interface DataManageService {
    /**
     * 获取数据源信息
     * @return
     */
    @GetMapping("/datasource/pv/find/{id}")
    DatasourceInfo findDatasourceById(@PathVariable("id") Long id);

    /**
     * 获取用户所有的表权限字典
     * @param datasourceId
     * @param proId
     * @param userId
     * @return
     */
    @PostMapping("/privilegeManage/pv/getAllTablePrivilege")
    Map<String, Set<PrivilegeType>> getAllTablePrivilege(@RequestParam("datasourceId") Long datasourceId, @RequestParam("proId") Long proId, @RequestParam("userId") Long userId, @RequestBody Set<String> tables);

    /**
     * 获取用户所有的表权限字典
     * @param proName
     * @param username
     * @return
     */
    @GetMapping("/privilegeManage/pv/createUserRoleOfHive")
    Result createUserRoleOfHive(@RequestParam("proName")String proName,@RequestParam("username") String username) throws SQLException;

    /**
     * 创建用户在hdfs的家目录
     * @param proName
     * @param username
     */
    @GetMapping("/privilegeManage/pv/createUserHdfsHomeDir")
    Result createUserHdfsHomeDir(@RequestParam("proName")String proName,@RequestParam("username") String username) throws IOException;

    /**
     * 获取表信息
     * @return
     */
    @GetMapping("/tableManage/pv/getTableInfo")
    TableInfo getTableInfo(@RequestParam("datasourceId")Long datasourceId,@RequestParam("dbName") String dbName,@RequestParam("tableName") String tableName);
}
